// https://nuxt.com/docs/api/configuration/nuxt-config
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Components from "unplugin-vue-components/vite";
import { fileURLToPath } from 'url'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'



export default defineNuxtConfig({
  runtimeConfig: {
    // 只在服务器端可用的私有键
    apiSecret: '123',
    // public中的键值对再服务端和客户端都可以访问
    public: {
      /* 获取apibase 再组件中
      const config = useRuntimeConfig()
      const baseUrl = config.public.apiBase
      再根目录下的.env文件中配置VUE_APP_PUBLIC_API_BASE  注意 .env.development和.env.production  文件 不起作用
      */
      apiBase: process.env.VUE_APP_PUBLIC_API_BASE,
    },
  },
  alias: {
    '@': fileURLToPath(new URL('./assets/img', import.meta.url)),
  },
  devServer: {
    host: '0.0.0.0',
    port: 3001,
  },
  app: {
    baseURL: '/',
    head: {
      titleTemplate: '%s - 工具盒子',
      meta: [
        { charset: 'utf-8' },
        { hid: "keywords", name: "keywords", content: "json格式化、在线json" },
        { hid: "description", name: "description", content: "在线代码对比/合并工具方便程序员查找出2段代码间的差异，并能进行合并。" },
        { name: 'viewport', content: 'width=device-width, initial-scale=1' }
      ],
      link: [{ rel: 'icon', type: 'image/x-icon', href: 'favicon.ico' }],
    },
    rootId: 'nuxt_app',
    rootAttrs: {
      // class: 'theme-bg',
      /* 给根标签添加属性 */
    },
    rootTag: 'div',
    layoutTransition: false,/* 是否开启布局切换过度页面 */
  },
  css: [
    'element-plus/dist/index.css',
    // '~/assets/styles/_variables.scss',
  ],
  vite: {
    optimizeDeps: {
      include: ['element-plus','axios','lodash']
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "~/assets/styles/variables.scss" as *;@use "~/assets/styles/tailwind.scss";@use "~/assets/styles/index.scss";`
        }
      }
    },
    plugins: [
      AutoImport({
        resolvers: [
          ElementPlusResolver(),
          NaiveUiResolver()
        ]
      }),
      Components({
        dts: true,
        resolvers: [ElementPlusResolver(
           /* elementPlus全局配置 */
            {
              importStyle: true
            }
        ),NaiveUiResolver()]
      }),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(__dirname, 'assets/svg')],
      })
    ],
    build: {
      // target: 'es2019',
      outDir: 'dist',
      cssCodeSplit: true,
    },
    server:{
      /* 开启代理 */
      proxy:{
        '/api': {
          target: 'http://127.0.0.1:8090',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    }
  },
  modules: [
    '@vueuse/nuxt',
    '@nuxtjs/sitemap',
    '@nuxtjs/i18n',
    'nuxtjs-naive-ui',
    ['@pinia/nuxt',{
      autoImports: ['defineStore'],
      disableVuex: true,
      // persist: {
      //   enabled: true,
      //   strategies: [
      //     { key: 'user', storage: localStorage },
      //     { key: 'cart', storage: sessionStorage }
      //   ]
      // },
    }],
    'pinia-plugin-persistedstate/nuxt',/* pinia 本地持久化 */
    '@element-plus/nuxt',
    '@nuxtjs/tailwindcss'
  ],
  vueuse: {
    ssrHandlers: true
  },
  elementPlus: {
    icon: 'ElIcon',
    importStyle: 'scss',
    // themes: ['dark'],
    defaultLocale: 'zh-cn', // 设置为中文
  },
  piniaPluginPersistedstate:{
    storage: 'localStorage',/* 存储方式 */
    debug: true
  },
  i18n: {
    // baseUrl: 'https://www.taskease.info/', // 设定域名前缀，这样在生成link 的href 会是绝对路径
    strategy: 'no_prefix', //url中自动增加语言前缀
    langDir: 'locales',
    locales: [
      { name:"中文",code: 'zh', file: 'zh.ts' },
      { name:"English",code: 'en', file: 'en.ts' },
    ],
    defaultLocale: 'zh',/* 默认语言 */
    lazy: true, //语言文件懒加载
    detectBrowserLanguage: { // 开启浏览器默认使用语言检测，如果浏览器使用zh，则进入浏览器会自动跳转中文
      useCookie: true, // 使用cookie
      alwaysRedirect: true // 每次重新进入网页，都是自动跳转对应的语言页面
    }
  },
  tailwindcss: {
    configPath: './tailwind.config.js',
    cssPath: './assets/style/tailwind.scss',
  },
  plugins: [
    // { src: '~/plugins/vuesax.ts', mode: 'client' }
  ],
  nitro: {
    minify: true,
    sourceMap: false,
    esbuild: {
        options: {
          target: 'esnext',
        },
    }
    /* 代理处理 */
    // devProxy: {
    //   '/api': {
    //     target: 'http://localhost:3001',
    //     changeOrigin: true,
    //   }
    // }
  },
  components: [
    {
      path: '~/components',
      extensions: ['.vue']
    }
  ],
  /* 自动引入的目录 */
  imports: {
    dirs: ["store","apis","constant"],
  },
  compatibilityDate: '2024-04-03',
  devtools: { enabled: true },
  ssr:true
})
